//
// Created by nicemoe on 2021/8/1.
//

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    int nights = 100;
    int *pt = new int;
    *pt = 1001;
    cout << "night: " << nights << " location:" << &nights << endl;
    cout << "int: " << *pt << " location:" << pt << endl;

    double *pd = new double;
    *pd = 10000001.0;
    cout << "double pd: " << *pd << " location:" << pd << "location of pointer pd: " << &pd << endl;

    cout << "size of pt = " << sizeof(pt) << " size of *pt =" << sizeof(*pt) << endl;
    cout << "size of pd = " << sizeof(pd) << " size of *pd = " << sizeof(*pd) << endl;
    //delete只能释放 new出来的的 如果内存不足new 出来的对象会为0 代表空指针
    delete pt;
    delete pd;

    int *psome = new int[10];
    delete[] psome;

    char food[] = "carrots";
    strcpy(food, "flan");
    cout << *(food + sizeof food - 2) <<endl;

    int m = 10, n = 20;
    //指针指向的地址的值不可以更改
    const int *p = &m;
    p = &n;
    cout << *p <<endl;
    //指针指向的地址不能更改
    int * const p1 = &m;
    *p1 = 30;
    cout << *p1 <<" " << m<<endl;

    //指针指向的地址和地址的值都不可以更改
   const  int * const p2 = &m;
    return 0;
}

